const { ccclass, property } = cc._decorator;
import pagePhysicsControl from '../cont/pagePhysicsControl';
import baseView from '../../../../app/base/baseView';
@ccclass
export default class pagePhysics extends baseView {
    @property(cc.Camera)
    waterCamera: cc.Camera = null;

    @property(cc.Node)
    waterContainer: cc.Node = null;

    @property(cc.Node)
    blockContainer: cc.Node = null;

    @property(cc.Sprite)
    waterShow: cc.Sprite = null;

    @property(cc.Prefab)
    waterPrefab: cc.Prefab = null;

    @property(cc.Prefab)
    icePrefab: cc.Prefab = null;

    @property(cc.Button)
    btnWater: cc.Button = null;

    @property(cc.Button)
    btnIce: cc.Button = null;

    onLoad() {
        const texture = new cc.RenderTexture();
        texture.initWithSize(this.waterShow.node.width, this.waterShow.node.height);
        const spriteFrame = new cc.SpriteFrame();
        spriteFrame.setTexture(texture);
        this.waterCamera.targetTexture = texture;
        this.waterShow.spriteFrame = spriteFrame;
    }

    start() {
        this.bindBtnEvent(this.btnWater, this.waterPrefab, this.waterContainer, 0.04);
        this.bindBtnEvent(this.btnIce, this.icePrefab, this.blockContainer, 0.2);
        window['page'] = this;
    }

    bindBtnEvent(btn: cc.Button, prefab: cc.Prefab, container: cc.Node, time: number) {
        btn.node.on('touchstart', function (this: pagePhysics) {
            this.schedule(function () {
                const node = cc.instantiate(prefab);
                node.parent = container;
                node.active = true;
                node.x = 0;
                node.y = 470;
            }, time);
        }, this);
        btn.node.on('touchend', function (this: pagePhysics) {
            this.unscheduleAllCallbacks();
        }, this)
    }
}